home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pj9_3.arc / PERROR.ASM < prev    next >
Assembly Source File  |  1991-10-07  |  972b  |  51 lines

  1.     title    perror - print error message
  2.     include    asm.inc
  3.  
  4.     public    perror
  5.  
  6.     .data
  7.     extrn    dgroup_segment:word
  8.  
  9.     .data?
  10. errmsg_buffer    db    100 dup(?)
  11.  
  12.  
  13.     .code
  14.     extn    clear_strerror,get_strerror,fwrite,save_most,strcpy_limit
  15.  
  16. ;;    perror
  17. ;
  18. ;    entry    DS:SI    optional message prefix
  19. ;    uses    AX
  20. ;
  21. perror    proc
  22.     call    save_most
  23.     mov    es,dgroup_segment[bp]    ; set destination pointer
  24.     mov    di,offset errmsg_buffer
  25.     lea    dx,[di+size errmsg_buffer-4] ; (-4 leaves room for ": " & \n)
  26.  
  27.     cmp    si,NULL_POINTER
  28.     je    per1            ; if no message prefix
  29.     call    strcpy_limit        ; else copy message prefix
  30.     mov    ax,' :'            ;  and ": "
  31.     stosw
  32.  
  33. per1:    call    get_strerror
  34.     jz    per2            ; if no error string
  35.     call    clear_strerror
  36.     call    strcpy_limit
  37.  
  38. per2:    mov    ax,NEWLINE_CHARS    ; append \n
  39.     stosw
  40.  
  41.     mov    bx,stderr        ; write text to standard error
  42.     mov    ds,dgroup_segment[bp]
  43.     lea    si,errmsg_buffer
  44.     mov    cx,di            ;  compute message byte count
  45.     sub    cx,si
  46.     call    fwrite
  47.     ret
  48. perror    endp
  49.  
  50.     end
  51.